package br.com.funaction.eventtcontrollerv2.controller;

import java.io.IOException;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import br.com.funaction.eventtcontrollerv2.entities.Franquia;

@SessionScoped
@ManagedBean
public class IndexMB {
	
	Franquia franquia = new Franquia();
	FacesContext contexto = FacesContext.getCurrentInstance();
	
	@PostConstruct
	public void init(){
		
		try{
			
			autenticacao();
			
		} catch(Exception e){
			
			this.franquia.setId(1);
		}
	}
	
	private void autenticacao() throws IOException{
		
		franquia = (Franquia) contexto.getExternalContext().getSessionMap().get("franquia");
		if(franquia == null){
			
			ExternalContext contextoExterno = contexto.getExternalContext();
			contextoExterno.redirect("/eventt-controller-v2/jsf/login/login.jsf");
			return;
		}
	}
}